<template>
  <!-- <router-view /> -->
  <router-view v-slot="{ Component }">
    <keep-alive>
      <component :is="Component" v-if="route.meta.h5Cache && oper === 'add'"></component>
    </keep-alive>
    <component :is="Component" v-if="!route.meta.h5Cache || (route.meta.h5Cache && oper !== 'add') "></component>
  </router-view>
</template>

<script setup>
import useSettingsStore from '@/store/modules/settings'
import { handleThemeStyle } from '@/utils/theme'
import {ref, nextTick, onMounted, watch} from "vue";
import { useRoute, useRouter } from 'vue-router'
import initListStore from '@/store/modules/initList'
let route = useRoute()
let router = useRouter()
let oper = ref(null)

const whiteList = ['login', 'register', '401', '403', '404','h5_login'];

watch(() => router.currentRoute.value.path, (to) => {
  oper.value = route.query.oper
})

onMounted( () => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme)
  })
  window.addEventListener('load', () => {
    
    sessionStorage.clear()
    let pathname = window.location.pathname
    let path = pathname.split('/')[1]
    console.log('path',path)
    if (whiteList.indexOf(path) === -1) {
      setTimeout( async ()=> {  
        await initListStore().publicList()
        await initListStore().baseList()
        await initListStore().budgetList()
        await initListStore().expenditureList()
        await initListStore().contractList()
        sessionStorage.setItem('isSystemList', '1')
        sessionStorage.setItem('isBudgetList', '1')
        sessionStorage.setItem('isExpenditureList', '1')
        sessionStorage.setItem('isContractList', '1')
        sessionStorage.setItem('isPublicList', '1')
      }) 
    }
  });
})
</script>
